<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:of="http://omnifaces.org/functions"
	template="/WEB-INF/templates/template.xhtml">
	
	<ui:define name="headIncludes">
		<f:event listener="#{ordemServicoBean.initialize}" type="preRenderView"/>
	</ui:define>
	
	<ui:define name="pageName">Consultar Ordem de Serviço</ui:define>
	
	<ui:define name="buttons">
		<p:commandButton value="Nova" style="height:28px;" action="#{ordemServicoBean.changeToNew}" icon="ui-icon-plus"/>
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages globalOnly="false" autoUpdate="true" />
				<h:panelGrid columns="8">
					<h:outputText value="Filtrar por:" />
					
					<p:inputText id="inputSearchFilterCod" style="width:100px;" value="#{ordemServicoBean.filterId}" maxlength="20" title="Número da OS"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButton').click(); }"/>
					<p:watermark value="Número da OS" for="inputSearchFilterCod"/>
					
					<p:inputText id="inputSearchFilter" style="width:300px;" value="#{ordemServicoBean.filter}" maxlength="100" title="Cliente"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButton').click(); }"/>
					<p:watermark value="Cliente" for="inputSearchFilter"/>
					
					<p:calendar id="inputSearchFilterData" value="#{ordemServicoBean.filterDataEmissao}" navigator="true"
						showButtonPanel="true" locale="pt_BR" pattern="dd/MM/yyyy" title="Data de emissão"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButton').click(); }"/>
					<p:watermark value="Data de emissão" for="inputSearchFilterData"/>
					
					<p:commandButton value="Consultar" style="height:28px;" action="#{ordemServicoBean.fillByFilter}" id="searchButton" icon="ui-icon-search"/>					
				</h:panelGrid>
				
				<div style="padding-top:10px;">
					<p:dataTable var="ordem" value="#{ordemServicoBean.ordensServico}"
						paginator="true" rows="10" paginatorPosition="bottom"
						emptyMessage="Não há registros" id="tableOrdemServico"> 					
				        
				        <p:column headerText="Número da OS" width="100" style="text-align:center;">  
				            <h:outputText value="#{ordem.numOs}" />  
				        </p:column>  
				  
				        <p:column headerText="Cliente">  
				            <h:outputText value="#{of:abbreviate(ordem.cliente.nome, 80)}" />  
				        </p:column> 
				        
				        <p:column headerText="Valor" width="120" style="text-align:center;">  
				            <h:outputText value="#{ordem.valor}">
				            	<f:convertNumber pattern="R$ #,###,##0.00" />
				            </h:outputText>
				        </p:column>  
				        
				        <p:column headerText="Data de emissão" width="100" style="text-align:center;">  
				            <h:outputText value="#{ordem.data}">
				           		<f:convertDateTime pattern="dd/MM/yyyy"/>
				           	</h:outputText>  
				        </p:column>
				        
				        <p:column headerText="" width="10">
							<p:commandButton icon="ui-icon-search"
								style="width: 24px; height: 24px;" action="#{ordemServicoBean.changeToDetail(ordem.numOs)}" title="Visualizar"/>
						</p:column> 	
			  	  </p:dataTable>
				</div>
			</div>
		</p:panel>						 
	</ui:define>
</ui:composition>